package com.omi.iberolactalpreventa.objects;

import java.util.ArrayList;

import com.omi.iberolactalpreventa.R;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AdapterConsumos extends BaseAdapter{

	protected Activity activity;
	protected ArrayList<ItmConsumo> items;
	
	public AdapterConsumos(Activity activity, ArrayList<ItmConsumo> items) {
		this.activity = activity;
		this.items = items;
	}

	@Override
	public int getCount() {
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		return items.get(position).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		View v = convertView;
		
		if(convertView==null)
		{
			LayoutInflater inf = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = inf.inflate(R.layout.item_consumo, null);
		}
		
		ItmConsumo c = items.get(position);
		TextView lblCodConsumo = (TextView)v.findViewById(R.id.lblCodConsumo);
		lblCodConsumo.setText(c.getCodigo());
		TextView lblDescripcionConsumo = (TextView) v.findViewById(R.id.lblDescripcionConsumo);
		lblDescripcionConsumo.setText(c.getDescripcion());
		TextView lblumConsumo = (TextView) v.findViewById(R.id.lblUmConsumo);
		lblumConsumo.setText(c.getUm());
		TextView txtcantconsum = (TextView) v.findViewById(R.id.txtcantconsum);
		txtcantconsum.setText(c.getCantidad()+"");
		return v;
	}

}
